package com.olymtech.jbricks.threadpool.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * @author haoting.wang
 * @date 2020/10/14 2:46 下午
 **/
@Data
@Slf4j
@ConfigurationProperties(prefix = "jbricks.threadpools")
public class DynamicThreadPoolProperties {


    /**
     * 负责人
     */
    private String owner;

    /**
     * apollo配置监控空间
     */
    private String apolloNamespace;

    /**
     * 应用名，报警提示用
     */
    private String applicationName;
    /**
     * 报警地址,目前使用企业微信
     */
    private String alarmApiUrl;

    /**
     * 告警时间间隔，单位分钟
     */
    private int alarmTimeInterval = 1;

    /**
     * 线程池配置
     */
    private List<ThreadPoolProperties> executors;


    public void doRefresh(Properties properties) {
        Map<String, String> dataMap = new HashMap<String, String>((Map) properties);
        ConfigurationPropertySource sources = new MapConfigurationPropertySource(dataMap);

        Binder binder = new Binder(sources);
        binder.bind("jbricks.threadpools", Bindable.ofInstance(this)).get();
    }
}
